from rest_framework import serializers
from users.models import User


# 登记注册
class UserRegisterModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'
        extra_kwargs = {
            'username': {
                'max_length': 20,
                'min_length': 4
            },

            'password': {
                'max_length': 20,
                'min_length': 8,
                'write_only': True

            },
        }

    # 重写create
    def create(self, validated_data):
        user = User.objects.create_user(**validated_data)

        return user


